package com.ltf.controller.tea;

import com.ltf.entity.*;
import com.ltf.entity.*;
import com.ltf.entity.*;
import com.ltf.service.MarkService;
import com.ltf.service.TaskService;
import com.ltf.service.XUserService;
import com.ltf.utils.PackJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/fore/tea")
public class MyTeaController {
@Autowired
XUserService userService;
@Autowired
TaskService taskService;
@Autowired
    MarkService markService;
public MyTeaController(){}

    @GetMapping("/findMyTask")
    public XJson findMyTask(){
        Object phone = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        XUser newUser = this.userService.findByPhone((String) phone);
        if (newUser == null) {
            return PackJson.packX(404, "用户未发现", (Object)null);
        } else {
            List<Task> tasks = this.taskService.findByTid(newUser.getUid());

            return PackJson.packX(200, "", tasks);
        }
    }

    @PostMapping("/findByClznoAndCno")//查询某班级某课程的评分
    public XJson findMark(String clzno,String cno,Integer termId){
        System.out.println("clzno="+clzno);
        System.out.println("cno="+cno);
        System.out.println("termId="+termId);
        List<MarkInfo> byClznoCno = markService.findByClzCno(clzno, cno,termId);
        return PackJson.packX(200,"",byClznoCno);
    }

    @PostMapping("/addMark")//添加评分
    public XJson addMark(@RequestBody List<Mark> marks){
        markService.doMark(marks);
        return PackJson.packX(200, "", "");
    }
}
